unit Weapon_Storage;

interface
uses
AsphyreDef, Graphics, Classes, StrUtils, SysUtils, TypInfo, Thing_Storage;


const
//Weapons
{W_Hands=0;
W_Bita=1;
W_Knife=2;
W_Sword=3;
W_JapanSword=4;
W_Fire=5;
W_PnevPistol=6;
W_Pistol=7;
W_UZI=8;
W_AK47=9;
W_Shotgun=10;
W_SniperRiffle=11;
W_Minigun=12;
W_Flamer=13;
W_MolotovKokteil=14;
W_RocketFire=15;
W_X3=16;
W_Tesak=17;
W_SmallFlame=18;
W_SmallFlameGround=19;
W_PlasmaRiffle=20;
W_PlasmaShotgun=21;
W_PlasmaMachineGun=22;
W_PlasmaBall=23;       }

//Weapon Class
WC_MeleeFight=0;
WC_Gun=1;
WC_Explosion=2;
WC_Fire=3;
WC_Laser=4;
WC_Plasma=5;

//Weapon Types
WT_Hands=0;
WT_Melee=1;
WT_Knife=2;
WT_Pistol=3;
WT_Machinegun=4;
WT_Riffle=5;
WT_Shotgun=6;
WT_Throwing=7;
WT_Minigun=8;
WT_BigGun=9;

type
  TWeapon = class (TThing)
  private
  //phisics
    FMelee:boolean;
    FMeleeRange:single;

    FFeedBack:single;

    FStunning:single;
    FStunningChance:single;

    FDamage:single;

    FRicoshet:boolean;

    FWeaponStyle:string;
    FWeaponClass:byte;
    FWeaponType:integer;

    FBMass:single;

    FMission:boolean;
    FMissionStops:boolean;
    FMissionByAir:boolean;
    FMissionMaxLength:single;
    FMissionPoint:TPoint2;

    FBCount:byte;
    FCountness:boolean;
    FReload:single;
    FCount:integer;

    FFireSpeed:single;

    FTickAcc:single;

    FUnstopable:boolean;
    FFire:boolean;
    FFlying:boolean;
    FStartImpuls:boolean;

    FExplosive:boolean;
    FExplosiveRadius:single;

    FFiring:boolean;
    FFiringCount:integer;
    FFiringRadius:single;
    FFiringTimeOut:single;

    FPoisoning:boolean;
    FPoisonSpeed:single;

    FFlashFire:boolean;

    FLaser:boolean;

    FRandSpeed:single;
    FMaxSpeed:single;
    FAcceleration:single;

    FOptics:boolean;

    FRandomMax:single;
    FRandomAccelerate:single;

    FDoCollision:boolean;
    FCollisionRadius:integer;

  //Srcipts
    FCreateScript,FMoveScript,FCollisionScript,FDeadScript:string;

  //art
    FSmoking:boolean;
    FSmokingLength:single;
    FScaling,FColoring:boolean;

    FParticles:boolean;
    FParticleImage:string;
    FParticleSColor:cardinal;
    FParticleEColor:cardinal;
    FParticleSpeed:single;
    FParticleDeathSpeed:single;
    FParticleSScaleX,FParticleSScaleY:single;
    FParticleEScaleX,FParticleEScaleY:single;
    FParticleRandomX:single;
    FParticleFx:cardinal;

    FfxEffect:cardinal;
    FSpin:single;
    FFlipX,FFlipY:boolean;
    FSmokeColor1,FSmokeColor2:TColor;

    FSColor,FEColor:cardinal;
    FSScaleX,FSScaleY:single;
    FEScaleX,FEScaleY:single;

    FAnimCount,FAnimStart:cardinal;
    FAnimSpeed:single;
    Fz:integer;

    FTransparenting:boolean;
  public
    procedure LoadFromFile(FileName:String);
    procedure CopyValuesFrom(Weapon:TWeapon); overload;
  published
    //phisics
    property Melee:boolean read FMelee write FMelee;
    property MeleeRange:single read FMeleeRange write FMeleeRange;

    property FeedBack:single read FFeedBack write FFeedBack;

    property Stunning:single read FStunning write FStunning;
    property StunningChance:single read FStunningChance write FStunningChance;

    property Damage:single read FDamage write FDamage;

    property Ricoshet:boolean read FRicoshet write FRicoshet;

    property WeaponStyle:string read FWeaponStyle write FWeaponStyle;
    property WeaponClass:byte read FWeaponClass write FWeaponClass;
    property WeaponType:integer read FWeaponType write FWeaponType;

    property BMass:single read FBMass write FBMass;

    property Mission:boolean read FMission write FMission;
    property MissionStops:boolean read FMissionStops write FMissionStops;
    property MissionByAir:boolean read FMissionByAir write FMissionByAir;
    property MissionMaxLength:single read FMissionMaxLength write FMissionMaxLength;
    property MissionPoint:TPoint2 read FMissionPoint write FMissionPoint;

    property BCount:byte read FBCount write FBCount;
    property Countness:boolean read FCountness write FCountness;
    property Reload:single read FReload write FReload;
    property Count:integer read FCount write FCount;

    property FireSpeed:single read FFireSpeed write FFireSpeed;

    property TickAcc:single read FTickAcc write FTickAcc;

    property Unstopable:boolean read FUnstopable write FUnstopable;
    property Fire:boolean read FFire write FFire;
    property Flying:boolean read FFlying write FFlying;
    property StartImpuls:boolean read FStartImpuls write FStartImpuls;

    property Explosive:boolean read FExplosive write FExplosive;
    property ExplosiveRadius:single read FExplosiveRadius write FExplosiveRadius;

    property Firing:boolean read FFiring write FFiring;
    property FiringCount:integer read FFiringCount write FFiringCount;
    property FiringRadius:single read FFiringRadius write FFiringRadius;
    property FiringTimeOut:single read FFiringTimeOut write FFiringTimeOut;

    property Poisoning:boolean read FPoisoning write FPoisoning;
    property PoisonSpeed:single read FPoisonSpeed write FPoisonSpeed;

    property FlashFire:boolean read FFlashFire write FFlashFire;

    property Laser:boolean read FLaser write FLaser;

    property RandSpeed:single read FRandSpeed write FRandSpeed;
    property MaxSpeed:single read FMaxSpeed write FMaxSpeed;

    property Optics:boolean read FOptics write FOptics;

    property RandomMax:single read FRandomMax write FRandomMax;
    property RandomAccelerate:single read FRandomAccelerate write FRandomAccelerate;

    property DoCollision:boolean read FDoCollision write FDoCollision;
    property CollisionRadius:integer read FCollisionRadius write FCollisionRadius;

    //Srcipts read write
    property CreateScript:string read FCreateScript write FCreateScript;
    property MoveScript:string read FMoveScript write FMoveScript;
    property CollisionScript:string read FCollisionScript write FCollisionScript;
    property DeadScript:string read FDeadScript write FDeadScript;

    //art read write
    property Smoking:boolean read FSmoking write FSmoking;
    property SmokingLength:single read FSmokingLength write FSmokingLength;
    property Scaling:boolean read FScaling write FScaling;
    property Coloring:boolean read FColoring write FColoring;

    property Particles:boolean read FParticles write FParticles;
    property ParticleImage:string read FParticleImage write FParticleImage;
    property ParticleSColor:cardinal read FParticleSColor write FParticleSColor;
    property ParticleEColor:cardinal read FParticleEColor write FParticleEColor;
    property ParticleSpeed:single read FParticleSpeed write FParticleSpeed;
    property ParticleDeathSpeed:single read FParticleDeathSpeed write FParticleDeathSpeed;
    property ParticleSScaleX:single read FParticleSScaleX write FParticleSScaleX;
    property ParticleSScaleY:single read FParticleSScaleY write FParticleSScaleY;
    property ParticleEScaleX:single read FParticleEScaleX write FParticleEScaleX;
    property ParticleEScaleY:single read FParticleEScaleY write FParticleEScaleY;
    property ParticleRandomX:single read FParticleRandomX write FParticleRandomX;
    property ParticleFx:cardinal read FParticleFx write FParticleFx;

    property fxEffect:cardinal read FfxEffect write FfxEffect;
    property Spin:single read FSpin write FSpin;
    property FlipX:boolean read FFlipX write FFlipX;
    property FlipY:boolean read FFlipY write FFlipY;
    property SmokeColor1:TColor read FSmokeColor1 write FSmokeColor1;
    property SmokeColor2:TColor read FSmokeColor2 write FSmokeColor2;

    property SColor:cardinal read FSColor write FSColor;
    property EColor:cardinal read FEColor write FEColor;
    property SScaleX:single read FSScaleX write FSScaleX;
    property SScaleY:single read FSScaleY write FSScaleY;
    property EScaleX:single read FEScaleX write FEScaleX;
    property EScaleY:single read FEScaleY write FEScaleY;

    property AnimCount:cardinal read FAnimCount write FAnimCount;
    property AnimStart:cardinal read FAnimStart write FAnimStart;
    property AnimSpeed:single read FAnimSpeed write FAnimSpeed;
    property z:integer read Fz write Fz;

    property Transparenting:boolean read FTransparenting write FTransparenting;
  end;

  TWeapon_Storage = class
  private
    FWeapons:array of TWeapon;
    function GetWeapon(Index:string):TWeapon;
  public
    property Weapon[Index:string]:TWeapon read GetWeapon;
    procedure AddFromFile(FileName:string);
  end;

function GetWeaponFromFile(FileName:string):TWeapon;

implementation

function GetWeaponFromFile(FileName:string):TWeapon;
begin
  Result:=TWeapon.Create;
  with Result do
  begin
    DoCollision:=true;
    Transparenting:=true;
    SColor:=$FFFFFFFF;
    EColor:=$FFFFFFFF;
    BCount:=1;
    z:=2;
    LoadFromFile(FileName);
  end;
end;

procedure TWeapon.CopyValuesFrom(Weapon:TWeapon);
begin
  inherited CopyValuesFrom(Weapon);
  FMelee:=Weapon.FMelee;
  FMeleeRange:=Weapon.FMeleeRange;
  FFeedBack:=Weapon.FFeedBack;
  FStunning:=Weapon.FStunning;
  FStunningChance:=Weapon.FStunningChance;
  FDamage:=Weapon.FDamage;
  FRicoshet:=Weapon.FRicoshet;
  FWeaponStyle:=Weapon.FWeaponStyle;
  FWeaponClass:=Weapon.FWeaponClass;
  FWeaponType:=Weapon.FWeaponType;
  FBMass:=Weapon.FBMass;
  FMission:=Weapon.FMission;
  FMissionStops:=Weapon.FMissionStops;
  FMissionByAir:=Weapon.FMissionByAir;
  FMissionMaxLength:=Weapon.FMissionMaxLength;
  FMissionPoint:=Weapon.FMissionPoint;
  FBCount:=Weapon.FBCount;
  FCountness:=Weapon.FCountness;
  FReload:=Weapon.FReload;
  FCount:=Weapon.FCount;
  FFireSpeed:=Weapon.FFireSpeed;
  FTickAcc:=Weapon.FTickAcc;
  FUnstopable:=Weapon.FUnstopable;
  FFire:=Weapon.FFire;
  FFlying:=Weapon.FFlying;
  FStartImpuls:=Weapon.FStartImpuls;
  FExplosive:=Weapon.FExplosive;
  FExplosiveRadius:=Weapon.FExplosiveRadius;
  FFiring:=Weapon.FFiring;
  FFiringCount:=Weapon.FFiringCount;
  FFiringRadius:=Weapon.FFiringRadius;
  FFiringTimeOut:=Weapon.FFiringTimeOut;
  FPoisoning:=Weapon.FPoisoning;
  FPoisonSpeed:=Weapon.FPoisonSpeed;
  FFlashFire:=Weapon.FFlashFire;
  FLaser:=Weapon.FLaser;
  FRandomMax:=Weapon.FRandomMax;
  FRandomAccelerate:=Weapon.FRandomAccelerate;  
  FRandSpeed:=Weapon.FRandSpeed;
  FMaxSpeed:=Weapon.FMaxSpeed;
  FAcceleration:=Weapon.FAcceleration;
  FOptics:=Weapon.FOptics;
  FDoCollision:=Weapon.FDoCollision;
  FCollisionRadius:=Weapon.FCollisionRadius;
  FCreateScript:=Weapon.FCreateScript;
  FMoveScript:=Weapon.FMoveScript;
  FCollisionScript:=Weapon.FCollisionScript;
  FDeadScript:=Weapon.FDeadScript;
  FSmoking:=Weapon.FSmoking;
  FSmokingLength:=Weapon.FSmokingLength;
  FScaling:=Weapon.FScaling;
  FColoring:=Weapon.FColoring;
  FParticles:=Weapon.FParticles;
  FParticleImage:=Weapon.FParticleImage;
  FParticleSColor:=Weapon.FParticleSColor;
  FParticleEColor:=Weapon.FParticleEColor;
  FParticleSpeed:=Weapon.FParticleSpeed;
  FParticleDeathSpeed:=Weapon.FParticleDeathSpeed;
  FParticleSScaleX:=Weapon.FParticleSScaleX;
  FParticleSScaleY:=Weapon.FParticleSScaleY;
  FParticleEScaleX:=Weapon.FParticleEScaleX;
  FParticleEScaleY:=Weapon.FParticleEScaleY;
  FParticleRandomX:=Weapon.FParticleRandomX;
  FParticleFx:=Weapon.FParticleFx;
  FfxEffect:=Weapon.FfxEffect;
  FSpin:=Weapon.FSpin;
  FFlipX:=Weapon.FFlipX;
  FFlipY:=Weapon.FFlipY;
  FSmokeColor1:=Weapon.FSmokeColor1;
  FSmokeColor2:=Weapon.FSmokeColor2;
  FSColor:=Weapon.FSColor;
  FEColor:=Weapon.FEColor;
  FSScaleX:=Weapon.FSScaleX;
  FSScaleY:=Weapon.FSScaleY;
  FEScaleX:=Weapon.FEScaleX;
  FEScaleY:=Weapon.FEScaleY;
  FAnimCount:=Weapon.FAnimCount;
  FAnimStart:=Weapon.FAnimStart;
  FAnimSpeed:=Weapon.FAnimSpeed;
  Fz:=Weapon.Fz;
  FTransparenting:=Weapon.FTransparenting;
end;

procedure TWeapon.LoadFromFile(FileName:string);
var
S:TStringList;
str,r,d:string;
c1,c2,i:integer;
begin
  S:=TStringList.Create;
  S.LoadFromFile(FileName);
  str:=s.Text;
  S.Free;
  while Pos('//',str)>0 do
  Delete(str,Pos('//',str),PosEx(#13#10,str,Pos('//',str))-Pos('//',str)+2);
  while Pos(#13#10,str)>0 do
  Delete(str,Pos(#13#10,str),2);
  while length(str)>0 do
  begin
    d:=copy(str,1,pos('=',str)-1);
    Delete(str,1,pos('=',str));
    c1:=Pos(';',str);
    r:=Copy(str,1,c1-1);
    case PropType(TWeapon,d) of
      tkFloat: SetPropValue(Self,d,StrToFloat(r));
      tkString,tkLString,tkWString: SetPropValue(Self,d,r);
      tkInteger: SetPropValue(Self,d,StrToInt64(r));
      tkEnumeration: SetPropValue(self,d,StrToBool(r));
    end;
    Delete(str,1,c1);
  end;
end;


function TWeapon_Storage.GetWeapon(Index:string):TWeapon;
var
i:integer;
begin
  for i := 0 to length(FWeapons)-1 do
  if Index=FWeapons[i].ID then
  begin
    result:=FWeapons[i];
    break;
  end;
end;

procedure TWeapon_Storage.AddFromFile(FileName:string);
var
z:integer;
begin
  z:=length(FWeapons);
  SetLength(FWeapons,z+1);
  FWeapons[z]:=GetWeaponFromFile(FileName);
end;

initialization
RegisterClass(TWeapon);

end.


